package com.ruoyi.project.shop.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.shop.domain.LitemallGrouponRules;
import com.ruoyi.project.shop.service.ILitemallGrouponRulesService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 团购规则Controller
 * 
 * @author ruoyi
 * @date 2020-03-11
 */
@RestController
@RequestMapping("/shop/rules")
public class LitemallGrouponRulesController extends BaseController
{
    @Autowired
    private ILitemallGrouponRulesService litemallGrouponRulesService;

    /**
     * 查询团购规则列表
     */
    @PreAuthorize("@ss.hasPermi('shop:rules:list')")
    @GetMapping("/list")
    public TableDataInfo list(LitemallGrouponRules litemallGrouponRules)
    {
        startPage();
        List<LitemallGrouponRules> list = litemallGrouponRulesService.selectLitemallGrouponRulesList(litemallGrouponRules);
        return getDataTable(list);
    }

    /**
     * 导出团购规则列表
     */
    @PreAuthorize("@ss.hasPermi('shop:rules:export')")
    @Log(title = "团购规则", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(LitemallGrouponRules litemallGrouponRules)
    {
        List<LitemallGrouponRules> list = litemallGrouponRulesService.selectLitemallGrouponRulesList(litemallGrouponRules);
        ExcelUtil<LitemallGrouponRules> util = new ExcelUtil<LitemallGrouponRules>(LitemallGrouponRules.class);
        return util.exportExcel(list, "rules");
    }

    /**
     * 获取团购规则详细信息
     */
    @PreAuthorize("@ss.hasPermi('shop:rules:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(litemallGrouponRulesService.selectLitemallGrouponRulesById(id));
    }

    /**
     * 新增团购规则
     */
    @PreAuthorize("@ss.hasPermi('shop:rules:add')")
    @Log(title = "团购规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LitemallGrouponRules litemallGrouponRules)
    {
        return toAjax(litemallGrouponRulesService.insertLitemallGrouponRules(litemallGrouponRules));
    }

    /**
     * 修改团购规则
     */
    @PreAuthorize("@ss.hasPermi('shop:rules:edit')")
    @Log(title = "团购规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LitemallGrouponRules litemallGrouponRules)
    {
        return toAjax(litemallGrouponRulesService.updateLitemallGrouponRules(litemallGrouponRules));
    }

    /**
     * 删除团购规则
     */
    @PreAuthorize("@ss.hasPermi('shop:rules:remove')")
    @Log(title = "团购规则", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(litemallGrouponRulesService.deleteLitemallGrouponRulesByIds(ids));
    }
}
